<% content_for :css do %>
  <%= stylesheet_link_tag 'groups_index' %>
<% end %>
<% content_for :title do %>所有的员工分组<% end %>
<div id='groups' class="grid_15 groups">
  <div class="grid_15 head alpha omega">
    <div class="title">
      所有的分组<small>(共<%= @groups.size %>组)</small>
    </div>
  </div>
  <div class="grid_15 alpha">
    <div class="grid_15 alpha all_groups">       
      <% if flash[:success].present? %>
      <div id='success' class="grid_15">
        <div><%= flash[:success] %></div>
      </div>         
      <% end %>
      <div class="grid_15 alpha top">
        <div class="right">          
          <div class='cruds'>
            <div>
              <%= link_to '增加', new_group_url, :class => 'crud new', :title => '增加一名新员工' if current_user.is_admin? %>
            </div>
          </div>
        </div>
      </div>
      <% if @groups.empty? %>
        <div class="grid_15 no_group">无分组</div>
      <% end %>
      <% @groups.each do |group| %>
      <div id='group_<%= group.id %>' class='grid_15 alpha omega group <%= cycle '','h' %>'>
        <div class='grid_2 alpha logo'>
          <%= image_tag "users/users.png", :size => '50x50', :class => "logo" %>
          <% if group.admin? %>
          <div class="admin">    
            <%= link_to_function "管理员","", :title => '管理员'  %>       
          </div>
          <% end %>
        </div>
        <div class='grid_5 detail'>
          <div class='name'>
            <div>
              <%= group.name %>
            </div>
            <% if current_user.is_admin? %>
            <div>
              <%= link_to_function "移动","", :class => 'l_crud l_move', :title => '上下移动调整位置', :id => "move_group_#{group.id}"  %>
            </div>            
            <script type="text/javascript">
              $('#move_group_<%= group.id %>').mousedown(function(){
                $('#group_<%= group.id %>').addClass('dropping');
                $('.all_groups').addClass('sortable');
                $( ".all_groups" ).sortable({ 
                    items: '.group',
                    disabled:false,
                    update: function(event, ui) { 
                      $.post('<%= sort_groups_url %>', $(this).sortable('serialize',{async: true}));
                      console_debug( $(this).sortable('serialize'))
                    }
                });
              });
              $('#move_group_<%= group.id %>').mouseup(function(){
                $('#group_<%= group.id %>').removeClass('dropping');
                $('.all_groups').removeClass('sortable');
                $( ".all_groups" ).sortable({disabled:true});
              });
            </script>
            <% end %>
          </div>    
          <div class='remark'>
            <%= group.remark %>
          </div>
        </div>
        <% if current_user.is_admin? %>
        <div class='grid_2 omega tools'>
          <%= link_to "编辑资料",edit_group_url(group),  
              :method => :get,:title => '编辑该分组资料', :class => 'tool' %>
          <%= link_to "删除分组", group_url(group),
              :method => :delete,
              :title => '删除该分组',
              :class => 'tool',
              :confirm => "确定要删除该分组吗？"%>
        </div>
        <% end %>
        <div class='grid_10 users'>
          <b>组员：</b>
          <% group.users.each do |user| %>
            <%= link_to user.full_name,users_url(:group_id => group.id),
                :target => :_blank, 
                :title => "点击看『#{user.full_name}』同组的员工" %>
          <% end %>
        </div>
      </div>
      <% end %>
    </div>
  </div>
</div>  